package com.ityc.service.impl;

import com.ityc.mapper.EmpMapper;
import com.ityc.mapper.StudentMapper;
import com.ityc.pojo.ClazzCountOption;
import com.ityc.pojo.JobOption;
import com.ityc.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public JobOption getEmpJobData() {
        List< Map<String, Object>> list = empMapper.CountEmpJobData();
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.CountEmpGenderData();
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.CountStudentDegreeData();
    }

    @Override
    public ClazzCountOption getStudentCountData() {
        List<Map<String, Object>> countList = studentMapper.StudentCount();
        if (!CollectionUtils.isEmpty(countList)){
            List<Object> clazzList = countList.stream().map(dataMap -> dataMap.get("cname")).toList();
            List<Object> dataList = countList.stream().map(dataMap -> dataMap.get("scount")).toList();
            return new ClazzCountOption(clazzList,dataList);
        }
        return null;
    }
}
